package com.sc.nft.admin.rpc;

import com.sc.nft.admin.request.*;
import com.sc.nft.entity.req.*;
import com.sc.nft.entity.vo.EcologyPoolGetPoolNameByDaoIdVo;
import com.sc.nft.entity.vo.EcologyPoolHatchCollectionVo;
import com.sc.nft.entity.vo.ecologypool.*;
import com.sc.nft.enums.EcologyPoolTypeEnum;
import com.sc.nft.service.EcologyPoolService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @author 刘国航
 * @since 2024/7/16
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/rpc/ecologyPool")
@Api(tags = "生态池接口")
public class EcologyPoolRpc {

    private final EcologyPoolService ecologyPoolService;

    @ApiOperation(value = "排行榜查询", notes = "排行榜查询", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/communityServiceRankConfPage", produces = MediaType.APPLICATION_JSON_VALUE)
    public PageResult<EcologyPoolCommunityServiceRankConfVO> communityServiceRankConfPage(@RequestBody EcologyPoolCommunityServiceRankConfRequest request) {
        return PageResult.success(ecologyPoolService.communityServiceRankConfPage(request.getPageNo(), request.getPageSize(), request.getRankName()));
    }

    @ApiOperation(value = "新增排行榜", notes = "新增排行榜", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/createCommunityServiceRankConf", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<Boolean> createCommunityServiceRankConf(@RequestBody @Valid EcologyPoolCreateCommunityServiceRankConfRequest request) {
        return Result.success(ecologyPoolService.createCommunityServiceRankConf(request));
    }

    @ApiOperation(value = "获取榜单最大结束时间", notes = "获取榜单最大结束时间", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getMaxCommunityServiceRankEndTime", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<EcologyPoolMaxCommunityServiceRankEndTimeVo> getMaxCommunityServiceRankEndTime(@RequestBody @Valid EcologyPoolMaxCommunityServiceRankEndTimeRequest request) {
        return Result.success(ecologyPoolService.getMaxCommunityServiceRankEndTime(request));
    }

    @ApiOperation(value = "编辑排行榜", notes = "编辑排行榜", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updateCommunityServiceRankConf", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<Boolean> updateCommunityServiceRankConf(@RequestBody @Valid EcologyPoolUpdateCommunityServiceRankConfRequest request) {
        return Result.success(ecologyPoolService.updateCommunityServiceRankConf(request.getId(), request.getActivityRule(), request.getTopImage()));
    }

    @ApiOperation(value = "排行榜上下架", notes = "排行榜上下架", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updateCommunityServiceRankConfStatus", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<Boolean> updateCommunityServiceRankConfStatus(@RequestBody @Valid EcologyPoolUpdateCommunityServiceRankConfStatusRequest request) {
        return Result.success(ecologyPoolService.updateCommunityServiceRankConfStatus(request.getId(), request.getStatus()));
    }

    @ApiOperation(value = "删除排行榜", notes = "删除排行榜", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/deleteCommunityServiceRankConf", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<Boolean> deleteCommunityServiceRankConf(@RequestBody @Valid IdRequest request) {
        return Result.success(ecologyPoolService.deleteCommunityServiceRankConf(request.getId()));
    }

    @ApiOperation(value = "排行榜详情", notes = "排行榜详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/communityServiceRankConfDetail", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<EcologyPoolCommunityServiceRankConfDetailVO> communityServiceRankConfDetail(@RequestBody @Valid IdRequest request) {
        return Result.success(ecologyPoolService.communityServiceRankConfDetail(request.getId()));
    }

    @ApiOperation(value = "排行榜榜单-数据详情", notes = "排行榜榜单-数据详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/communityServiceRankPage", produces = MediaType.APPLICATION_JSON_VALUE)
    public PageResult<EcologyPoolCommunityServiceRankVO> communityServiceRankPage(@RequestBody @Valid IdPageRequest request) {
        return PageResult.success(ecologyPoolService.communityServiceRankPage(request.getPageNo(), request.getPageSize(), request.getId()));
    }

    @ApiOperation(value = "生态流水", notes = "生态流水", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/recordPage", produces = MediaType.APPLICATION_JSON_VALUE)
    public PageResult<EcologyPoolRecordRpcVO> recordPage(@RequestBody EcologyPoolRecordRpcRequest request) {
        return PageResult.success(ecologyPoolService.recordPage(request.getPageNo(), request.getPageSize(), request.getUserTel(), request.getPoolTypeList(), request.getFlowType(), request.getStartTime(), request.getEndTime(), request.getDaoId()));
    }

    @ApiOperation(value = "获取生态池积分", notes = "获取生态池积分", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getPoolData", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<Map<EcologyPoolTypeEnum, EcologyPoolDataVO>> getPoolData(@RequestBody EcologyPoolDataRpcRequest request) {
        return Result.success(ecologyPoolService.getPoolData(request.getTypeList(), request.getDaoId(), null));
    }

    @ApiOperation(value = "分配积分", notes = "分配积分", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/allocatePoints", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<Boolean> allocatePoints(@RequestBody EcologyPoolAllocatePointsRequest request) {
        return Result.success(ecologyPoolService.communityServiceCenterAllocatePoints(request.getOperationType(), request.getPoolType(), request.getUserId(), request.getLinkCount(), request.getLinkType(), request.getRemark()));
    }

    @ApiOperation(value = "批量分配积分", notes = "批量分配积分", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/batchAllocatePoints", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<Boolean> batchAllocatePoints(@RequestBody @Valid EcologyPoolBatchAllocatePointsRequest request) {
        return Result.success(ecologyPoolService.batchCommunityServiceCenterAllocatePoints(request));
    }

    @ApiOperation(value = "按手机号查询积分", notes = "按手机号查询积分", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/findPointsByUserTel", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<EcologyPoolFindPointsByUserTelVO> findPointsByUserTel(@RequestBody EcologyPoolFindPointsByUserTelRpcRequest request) {
        return Result.success(ecologyPoolService.findPointsByUserTel(request.getDaoId(), request.getUserTel(), request.getLinkType(), request.getPoolType()));
    }

    @ApiOperation(value = "按手机号列表查询积分", notes = "按手机号列表查询积分", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/findPointsByUserTelList", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<EcologyPoolUserUploadVo> findPointsByUserTelList(@RequestBody EcologyPoolUploadUserRpcRequest request) {
        return Result.success(ecologyPoolService.findPointsByUserTelList(request.getDaoId(), request.getLinkType(), request.getDataList(), request.getPoolType()));
    }

    @ApiOperation(value = "更新生态池名称", notes = "更新生态池名称", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updatePoolName", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<Boolean> updatePoolName(@RequestBody @Valid EcologyPoolUpdatePoolNameRpcRequest request) {
        return Result.success(ecologyPoolService.updatePoolName(request.getId(), request.getDaoId(), request.getPoolName()));
    }

    @ApiOperation(value = "新增排行榜-非玛特DAO", notes = "新增排行榜-非玛特DAO", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/createDaoCommunityServiceRankConf", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<Boolean> createDaoCommunityServiceRankConf(@RequestBody @Valid EcologyPoolCreateDaoCommunityServiceRankConfRpcRequest request) {
        return Result.success(ecologyPoolService.createDaoCommunityServiceRankConf(request));
    }

    @ApiOperation(value = "删除排行榜-非玛特DAO", notes = "删除排行榜-非玛特DAO", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/deleteDaoCommunityServiceRankConf", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<Boolean> deleteDaoCommunityServiceRankConf(@RequestBody @Valid IdRequest request) {
        return Result.success(ecologyPoolService.deleteDaoCommunityServiceRankConf(request.getId()));
    }

    @ApiOperation(value = "获取熔炼藏品", notes = "获取熔炼藏品", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/hatchCollectionList", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<List<EcologyPoolHatchCollectionVo>> hatchCollectionList(@RequestBody @Valid EcologyPoolHatchCollectionRpcRequest request) {
        return Result.success(ecologyPoolService.hatchCollectionList(request.getCollectionName(), request.getDaoId()));
    }

    @ApiOperation(value = "排行榜上下架-非玛特DAO", notes = "排行榜上下架-非玛特DAO", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updateDaoCommunityServiceRankConfStatus", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<Boolean> updateDaoCommunityServiceRankConfStatus(@RequestBody @Valid EcologyPoolUpdateCommunityServiceRankConfStatusRequest request) {
        return Result.success(ecologyPoolService.updateCommunityServiceRankConfStatus(request.getId(), request.getStatus()));
    }

    @ApiOperation(value = "排行榜详情-非玛特DAO", notes = "排行榜详情-非玛特DAO", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/daoCommunityServiceRankConfDetail", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<EcologyPoolDaoCommunityServiceRankConfDetailVo> daoCommunityServiceRankConfDetail(@RequestBody @Valid IdRequest request) {
        return Result.success(ecologyPoolService.daoCommunityServiceRankConfDetail(request.getId()));
    }

    @ApiOperation(value = "排行榜榜单-数据详情-非玛特DAO", notes = "排行榜榜单-数据详情-非玛特DAO", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/daoCommunityServiceRankPage", produces = MediaType.APPLICATION_JSON_VALUE)
    public PageResult<EcologyPoolDaoCommunityServiceRankVO> daoCommunityServiceRankPage(@RequestBody @Valid IdPageRequest request) {
        return PageResult.success(ecologyPoolService.daoCommunityServiceRankPage(request.getPageNo(), request.getPageSize(), request.getId()));
    }

    @ApiOperation(value = "排行榜榜单-查询-非玛特DAO", notes = "排行榜榜单-查询-非玛特DAO", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/daoCommunityServiceRankConfPage", produces = MediaType.APPLICATION_JSON_VALUE)
    public PageResult<EcologyPoolDaoCommunityServiceRankConfVo> daoCommunityServiceRankConfPage(@RequestBody @Valid EcologyPoolDaoCommunityServiceRankConfRequest request) {
        return PageResult.success(ecologyPoolService.daoCommunityServiceRankConfPage(request.getPageNo(), request.getPageSize(), request.getRankName(), request.getApprovalStatus(), request.getDaoId()));
    }

    @ApiOperation(value = "根据品牌获取生态池积分名称", notes = "根据品牌获取生态池积分名称", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getPoolNameByDaoId", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<EcologyPoolGetPoolNameByDaoIdVo> getPoolNameByDaoId(@RequestBody @Valid EcologyPoolGetPoolNameByDaoIdRequest request) {
        return Result.success(ecologyPoolService.getPoolNameByDaoId(request.getDaoId()));
    }

}
